package com.ruoyi.hotel.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.hotel.domain.dto.HlMemberRecordDTO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hotel.domain.HlUser;
import com.ruoyi.hotel.service.IHlUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户列表Controller
 * 
 * @author ruoyi
 * @date 2022-12-10
 */
@RestController
@RequestMapping("/hotel/hluser")
public class HlUserController extends BaseController
{
    @Autowired
    private IHlUserService hlUserService;

    /**
     * 查询用户列表列表
     */
    @PreAuthorize("@ss.hasPermi('hotel:hluser:list')")
    @GetMapping("/list")
    public TableDataInfo list(HlUser hlUser)
    {
        startPage();
        List<HlUser> list = hlUserService.selectHlUserList(hlUser);
        return getDataTable(list);
    }

    /**
     * 导出用户列表列表
     */
    @PreAuthorize("@ss.hasPermi('hotel:hluser:export')")
    @Log(title = "用户列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HlUser hlUser)
    {
        List<HlUser> list = hlUserService.selectHlUserList(hlUser);
        ExcelUtil<HlUser> util = new ExcelUtil<HlUser>(HlUser.class);
        util.exportExcel(response, list, "用户列表数据");
    }


    /**
     * 获取用户列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('hotel:hluser:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(hlUserService.selectHlUserById(id));
    }



    /**
     * 查询用户列表根据手机号
     */
    @PreAuthorize("@ss.hasPermi('hotel:hluser:phone')")
    @GetMapping("/phone")
    public TableDataInfo phone(@RequestParam(name = "phone") String phone)
    {
//        前端如果模糊查询，必须要用startPage()方法，否则前端的rows取值就很麻烦
//        对于getMapping()注解，要写上这个方法的最后一个uri值
//        对于权限这一块要在若依后台新增一个对应权限
//        对于接收参数，要用上RequestParm(name="参数名")注解 多个参数就一一对应上
//        传参需要注意在js文件的那个请求方法中，写上 params :{ 参数名: 参数，参数名： 参数....}
        startPage();
        List<HlUser> list = hlUserService.selectHlUserListByPhone(phone);
        return getDataTable(list);
    }



    /**
     * 新增用户列表
     */
    @PreAuthorize("@ss.hasPermi('hotel:hluser:add')")
    @Log(title = "用户列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HlUser hlUser)
    {

        String username = getUsername();
        hlUser.setCreateBy(username);
        hlUser.setUpdateBy(username);
        return toAjax(hlUserService.insertHlUser(hlUser));
    }

    /**
     * 修改用户列表
     */
    @PreAuthorize("@ss.hasPermi('hotel:hluser:edit')")
    @Log(title = "用户列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HlUser hlUser)
    {
        return toAjax(hlUserService.updateHlUser(hlUser));
    }

    /**
     * 删除用户列表
     */
    @PreAuthorize("@ss.hasPermi('hotel:hluser:remove')")
    @Log(title = "用户列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hlUserService.deleteHlUserByIds(ids));
    }
}
